package com.hxh.service;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.plugins.Page;
import com.hxh.dao.ProjectDatasourceDao;
import com.hxh.entity.ProjectDatasource;
import com.hxh.entity.input.ProjectDatasourceInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
@Slf4j
public class ProjectDatasourceService {
    @Resource ProjectDatasourceDao projectDatasourceDao;


    public boolean insert(ProjectDatasource pojo) {

        boolean res = projectDatasourceDao.insert(pojo) > 0;

        return res;
    }

    public int insertList(List<ProjectDatasourceInput> pojo) {
        if(CollectionUtils.isEmpty(pojo)){
            return 0;
        }

        int res = projectDatasourceDao.insertList(pojo);
        return res;
    }

    public List<ProjectDatasource> select(ProjectDatasourceInput pojo) {
        return projectDatasourceDao.select(pojo);
    }

    public boolean deleteById(Integer id){
        return projectDatasourceDao.deleteById(id) > 0;
    }

    public ProjectDatasource selectById(Integer id){
        if(id == null ) {
          return null;
        }
        return projectDatasourceDao.selectById(id);
    }
    public List<ProjectDatasource> selectByIds(List<String> ids){
        if (CollectionUtil.isEmpty(ids)){
            return null;
        }
        return projectDatasourceDao.selectByIds(ids);
    }

    public void listPage(Page<ProjectDatasource> page, ProjectDatasourceInput pojo) {
        page.setRecords(projectDatasourceDao.listPage(page, pojo));
    }

    public boolean update(ProjectDatasource pojo) {

        return projectDatasourceDao.update(pojo) > 0;
    }

    public boolean updateSelective(ProjectDatasourceInput pojo) {

        int res = projectDatasourceDao.updateSelective(pojo);
        return res > 0;
    }

    public List<ProjectDatasource> listAll() {
        return projectDatasourceDao.listAll();
    }

}
